/**
 * Copyright (C) 2010 DustedPixels.com
 */
package com.dustedpixels.cirt.model.machine.spectrum.rom;

import com.dustedpixels.cirt.model.core.Circuit;
import com.dustedpixels.cirt.model.core.In;
import com.dustedpixels.cirt.model.core.Out;
import com.dustedpixels.cirt.model.core.Script;

/**
 * Rom
 *
 * @author Michal Pociecha-Los (micapolos@gmail.com)
 */
@Circuit
public final class ByteRam {
  @In public int address;
  @In @Out public int data;
  
  private final byte[] byteArray;
  private final int addressMask;

  public ByteRam(byte[] byteArray, int addressMask) {
    this.byteArray = byteArray;
    this.addressMask = addressMask;
  }
  
  @Script
  public void write() {
    byteArray[address & addressMask] = (byte) data;
  }
  
  @Script
  public void read() {
    data = byteArray[address & addressMask] & 0xFF;
  }
}
